<?php

namespace IMT\EventBundle\Entity;


use Doctrine\ORM\Mapping as ORM;
use IMT\EventBundle\Entity\BaseEvent;
use IMT\EventBundle\Models\EventInterface;
use IMT\EventBundle\Entity\File;
use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap;

/**
 * IMT\EventBundle\Entity\Meeting
 *
 * @ORM\Table(name="meeting")
 * @ORM\Entity
 */
class Meeting extends BaseEvent
{
	
// 	/**
// 	 * @var integer $id
// 	 *
// 	 * @ORM\Column(name="id", type="integer")
// 	 * @ORM\Id
// 	 * @ORM\GeneratedValue(strategy="AUTO")
// 	 * @Soap\ComplexType("int", nillable=true)
// 	 */
// 	protected $id;
      
	
	protected $type = 'meeting';
	
	/**
     * @ORM\OneToMany(targetEntity="IMT\Plugins\OrderBundle\Entity\Ordre", mappedBy="event", cascade={"all"})
     */
	protected $orders;
	
	/**
	 * @ORM\Column(name="note", type="text", nullable=true)
	 */
	protected $note = '';
	
	/**
	 * @ORM\Column(name="address", type="text", nullable=true)
	 */
	protected $address = '';
	
	public function getType()
	{
		return 'meeting';
	}
    
    /**
     * {@inheritDoc}
     */
    public function convertEventToJson()
    {
    	$vars = get_object_vars($this);
    
    	foreach ($vars as $key => $value)
    	{
    		if(is_object($value)){
    			if(false === $value instanceof \DateTime)
    				unset($vars[$key]);
    		}
    	}
    	
    	return json_encode($vars);
    }
    
    /**
     * {@inheritDoc}
     */
    public function getId()
    {
    	return $this->id;
    }
	/**
	 * @return the $orders
	 */
	public function getOrders() {
		return $this->orders;
	}

	/**
	 * @return the $address
	 */
	public function getAddress() {
		return $this->address;
	}

	/**
	 * @param field_type $address
	 */
	public function setAddress($address) {
		$this->address = $address;
	}

	/**
	 * @return the $note
	 */
	public function getNote() {
		return $this->note;
	}

	/**
	 * @param field_type $orders
	 */
	public function setOrders($orders) {
		$this->orders = $orders;
	}
	
	/**
	 * add order
	 *
	 * @param IMT\Plugins\OrderBundle\Entity\Ordre $order
	 */
	public function addOrder(\IMT\Plugins\OrderBundle\Entity\Ordre $order)
	{
		if(!$this->hasOrder($order))
			$this->orders[] = $order;
	}
	
	public function hasOrder(\IMT\Plugins\OrderBundle\Entity\Ordre $order)
	{
		$existingOrderId = array();
		foreach($this->orders as $value)
			$existingOrderId[] = $value->getId();
	
		return in_array($order, $existingOrderId, true);
	}

	/**
	 * @param field_type $note
	 */
	public function setNote($note) {
		$this->note = $note;
	}

    
}